package com.tangruojie.functionInterface;

import com.tangruojie.entity.Author;
import com.tangruojie.stream.StreamDemoTest;

import java.util.List;
import java.util.function.Predicate;

/**
 * 函数式接口中的 default 方法
 */
public class FunctionDemo02 {

    public static void main(String[] args) {

        List<Author> authors = StreamDemoTest.getAuthors();

        authors.stream()
                .filter(
                        new Predicate<Author>() {
                            @Override
                            public boolean test(Author author) {
                                return author.getAge() > 17;
                            }
                        }.and(
                                new Predicate<Author>() {
                                    @Override
                                    public boolean test(Author author) {
                                        return author.getName().length() > 1;
                                    }
                                }
                        ).or(
                                new Predicate<Author>() {
                                    @Override
                                    public boolean test(Author author) {
                                        return author.getAge() < 15;
                                    }
                                }
                        )
                )
                .distinct()
                .forEach(author -> System.out.println(author.getAge() + " : " + author.getName()));

    }

}
